<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="presentation.PresentationsBean"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 <%@page import="db.Album"%>
<%@page import="java.util.List"%>
<%@page import="presentation.Get16ImagesBean"%>   
<%@page import="presentation.GetAllAlbumsBean"%>
<head>
	<link rel="stylesheet" type="text/css" href="css/styleGallery.css" />  
	<link rel="stylesheet" type="text/css" href="css/ViewPicture.css" /> 
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Пациенти</title>
</head>

<body id="bd">

<div id="container">
	<my:header/>
	 <%	
	 
	 Integer pageNum =null;
		 try{
		 	pageNum = Integer.parseInt(request.getParameter("page"));
		}catch( Exception e){  			
			pageNum=1;
		};  
		GetAllAlbumsBean b = new GetAllAlbumsBean();
		
	    Long userid=(Long)session.getAttribute("userid");
	    if (userid == null) {
	    	%>
	    	<c:redirect url="Home.jsp" > </c:redirect>
	    	<%
	    }
     	List<Album> userAlbums = null;
     	Long currentAlbumId = null;
     	long allAlbNum=0L;
     	String root = request.getParameter("root");
     	Boolean search=null;
   	 	try{
   			 search = (Boolean)request.getAttribute("search");
   			 if (search == null) {
   				 search = false;
   			 }
   		}catch( Exception e){  			
   			search = false;
   		};
   		if (search) {
   			userAlbums = (List<Album>)request.getAttribute("search_albums");	
	   	} else {
	     	 if(root == null) {
	     		//userAlbums = (List<Album>)session.getAttribute("user_albums");
	     		
	     		currentAlbumId = (Long)session.getAttribute("current_album_id");
	     		userAlbums=b.get16CildAlbumsByParentId(currentAlbumId,pageNum);
	     		allAlbNum= b.get16ChildAlbumsNum(currentAlbumId);
	     	 }
	     	 
	     	 
	     	 
	     	if(userAlbums == null) {
		   	 	userAlbums = PresentationsBean.getTopLevelAlbumsByUser(userid,pageNum);
		   	    allAlbNum= PresentationsBean.getTopLevelAlbumsByUserNum(userid);
	     	}
   		}
   	  %>
	<my:menulogin/>
	<!-- 
<% if(currentAlbumId != null) { %>
         <div id="uploadsite">
         <form name="myform" action="UploadServlet" method="post" enctype="multipart/form-data" id="form1">       

         <div id="uploadbox">
                 <div id="labelupl">   
                 Прикачване на снимки</div>
                     Име:<br>
                     <input name="user_file" type="file" value="Избери" style="width: 178px; height: 23px; float:left; background-color: #929292; font-weight: bold; font-size: 12px; color: #000;  float:right;"/>
                     <br>
                    <input class="button1" type="submit" value="прикачи" />
                    </div>     
          </form>
          </div>
<% } %>
          <br>
        <div id="uploadsite">
          <form action="AddAlbumServlet" id="form1" method="post">
                 <div id="uploadbox">
                 <div id="labelupl">Създаване на нов Албум</div>
                     Име:<br>
                     <input id="upload" name="album_name" type="text" />
                    <input class="button1" type="submit" value="създай" />
                    <input type="hidden" name="parent_id" value="<%=currentAlbumId%>" />
                    <input type="hidden" name="refer" value="MyAlbum.jsp" />
                    </div>   
            </form>
            </div>
           
       -->
		

   		<%
   		if (userAlbums.isEmpty()) {
   		%>
   		<div id="midcontainer">
   		<a href="?root=true">Пациенти</a> <%=PresentationsBean.getHTMLlink4album(currentAlbumId, userid) %>
   		<%
   			if (search) {
   		%>
   			<p id="err">Няма намерен пациент с зададеното ЕГН!</p>
   			<br />
   			<div id="page">
   			 <li><a class="number" href="Home.jsp"> &nbsp; Към всички снимки...<a></li>
   			</div>
   			
   			</div>
   		<%		
   			} else {
   		%>
   		<p id="err">Няма създадени пациенти до момента!</p>
   		<div id="page">
   			 <li><a class="number" href="Home.jsp?album_id=<%=currentAlbumId %>"> &nbsp; Преглед на снимките<a></li>
   		</div>
   		</div>
   		<%
   			}
   		}else{
   		%>
   		<div id="midcontainer"><a href="?root=true">корен</a> <%=PresentationsBean.getHTMLlink4album(currentAlbumId, userid) %>
   		<table align="center">
   		<% 	
   		 	 for (int i = 0; i < userAlbums.size(); i++){
   		 		 Album album = userAlbums.get(i);
   		 		 if (i % 4 == 0) {
   		 			 %>
   		 			 <tr></tr>
   		 			 <%
   		 		 }
   		%>        
   		<td>  
          		 <div id ="pic">
            	 	 <li style=" display:inline;float:left;"><!-- <a href="EnterInAlbumServlet?album_id=<%=album.getAlbumId() %>"> -->
            	 	 
            	 	 <a href="Home.jsp?album_id=<%=album.getAlbumId() %>"><img width="100" height="100" style="img-decoration:none; border-style:none;"src="img/folder_images.png"/></a></li>
            	 	 <li> <%=album.getAlbumName() %> </li>
             	 	<br>
            	 	 <li style="text-decoration:none;margin:0px 0px; padding:0px; display : inline;">
         		      <a href="EditAlbumServlet?album_id=<%=album.getAlbumId() %>" title="редактирай"><img style="img-decoration:none; border-style:none;" src="img/editFolder.png"/></a></li>
             	 	<li style="text-decoration:none;margin:0px 0px; padding:0px; display : inline;">
         	 	     <a href="DeleteAlbumServlet?album_id=<%=album.getAlbumId() %>" title="изтрий"><img style="img-decoration:none; border-style:none;" src="img/delFolder.png"/></a></li>
           		</div>
           	</td>	        
   		   <%};%>
   		   </table>
<%
if (userAlbums.size() <= 4) {
	%>
	<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
	<br /><br /><br /><br /><br />
	<br /><br />
	<%
} else if (userAlbums.size() <= 8) {
	%>
	<br /><br /><br /><br /><br /><br /><br />
	<%
} 
%>

   <% if(root == null) {	%>
    	<div id="page">
        	 <%
          	 if ((pageNum==1)&&(allAlbNum>1)){ %>
              	<li> Prev &nbsp;</li>		
   		      	<li> <a class="number" href="MyAlbum.jsp?album_id=<%=currentAlbumId %>&page=<%=++pageNum%>">&nbsp; Next<a></li>
          	<%}else if(( pageNum==allAlbNum )&&(allAlbNum==1)){
        	 %>
            	 <li>  Prev &nbsp;</li>		
   		   		  <li> <a class="number" href="Home.jsp?album_id=<%=currentAlbumId%>"> &nbsp; Next<a></li>		
          	<%}else if( pageNum==allAlbNum ){
        	 %>
            <li> <a class="number" href="MyAlbum.jsp?album_id=<%=currentAlbumId %>&page=<%=--pageNum%>">&nbsp; Prev<a></li>	
   		     <li> <a class="number" href="Home.jsp?album_id=<%=currentAlbumId%>"> &nbsp; Next<a></li>		
          <%}else{ %>
  	        	<li> <a class="number" href="MyAlbum.jsp?album_id=<%=currentAlbumId %>&page=<%=--pageNum%>">&nbsp; Prev<a></li>	
  	        	<%pageNum++;%>	
   				<li> <a class="number" href="MyAlbum.jsp?album_id=<%=currentAlbumId %>&page=<%=++pageNum%>">&nbsp; Next<a></li>
   			<%} %>
    </div>
   <%}else{ %>	   
  			 <div id="page">
        	 <%
           	if ((pageNum==1)&&(allAlbNum>1)){ %>
             	 <li> Prev &nbsp;</li>		
   		     	 <li> <a class="number" href="MyAlbum.jsp?root=true&page=<%=++pageNum%>">&nbsp; Next<a></li>
          	<%}else if(( pageNum==allAlbNum )&&(allAlbNum==1)){
        		 %>
           	  <li>  Prev &nbsp;</li>		
   		   	 <li>&nbsp; Next</li>
          	<%}else if(( pageNum==allAlbNum )&&(allAlbNum!=1)){
        		 %>
           	  <li> <a class="number" href="MyAlbum.jsp?root=true&page=<%=--pageNum%>">&nbsp; Prev<a></li>				
   				<li> &nbsp; Next</li>
          	<%}else{ %>
  	        	<li> <a class="number" href="MyAlbum.jsp?root=true&page=<%=--pageNum%>">&nbsp; Prev<a></li>	
  	        	<%pageNum++;%>	
   				<li> <a class="number" href="MyAlbum.jsp?root=true&page=<%=++pageNum%>">&nbsp; Next<a></li>
   			<%} %>
    </div>
    <%} %><!-- else for root!=null -->
		  </div><!-- midcontainer -->
	 <%};%>	 
<my:footer/>
</body>
</html>